"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        if (typeof b !== "function" && b !== null)
            throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.compareQuaternion = exports.subQuaternion = exports.distance = exports.RandomColor = void 0;
/*
 * @Author: hongbin
 * @Date: 2023-01-07 10:12:47
 * @LastEditors: hongbin
 * @LastEditTime: 2023-02-04 15:58:14
 * @Description:
 */
var THREE = require("three");
/**
 * 继承自THREE.Color的随机颜色
 */
var RandomColor = /** @class */ (function (_super) {
    __extends(RandomColor, _super);
    function RandomColor() {
        var _this = _super.call(this) || this;
        _this.r = Math.random();
        _this.g = Math.random();
        _this.b = Math.random();
        return _this;
    }
    return RandomColor;
}(THREE.Color));
exports.RandomColor = RandomColor;
function distance(x1, x2) {
    //都是负数  -3 => -5 = -2
    if (x1 < 0 && x2 < 0) {
        return (x2 * -1 - x1 * -1) * -1;
    }
    return x2 - x1;
}
exports.distance = distance;
/**
 * subQuaternion的减法
 */
function subQuaternion(old, ter) {
    var x = distance(old.x, ter.x);
    var y = distance(old.y, ter.y);
    var z = distance(old.z, ter.z);
    var w = distance(old.w, ter.w);
    return new THREE.Quaternion(x, y, z, w);
}
exports.subQuaternion = subQuaternion;
function quaternionToEuler(q) {
    return new THREE.Euler().setFromQuaternion(q);
}
/**
 * 计算两个旋转的差值 返回需要旋转角度小的那个Quaternion
 * 旋转90度和-270度都在一个位置 但是旋转-270度看起来就会转一圈再到角度 效果不好
 */
function compareQuaternion(q1, q2) {
    var subQ1 = subQuaternion(q1, q2);
    var subQ2 = subQuaternion(q2, q1);
    console.log(subQ1, subQ2);
    var subE1 = quaternionToEuler(subQ1);
    var subE2 = quaternionToEuler(subQ2);
    console.log(subE1, subE2);
}
exports.compareQuaternion = compareQuaternion;
